libname local "D:\My Documents\RESEARCH\RentBureau\Datasets";

libname local2 "M:\Data\RentBureau";


libname leases "M:\Data\RentBureau\Leases";

libname collect "M:\Data\RentBureau\Collections";


/********************************************/
/*           EXTRACTING LEASES              */
/********************************************/

data leases (drop= collection_id moveout_date_collections placement_date placed_amt balance_amt 
	          collected_amt collection_status);
set leases.leases;
lease_yr=year(begin_date);
lease_mo=month(begin_date);
last_act_yr=year(last_activity_date);
last_act_mo=month(last_activity_date);
if begin_date=. then do;
   lease_yr=year(movein_date);
   lease_mo=month(movein_date);
   end;
if lease_yr < 1980 or lease_yr > 2010 then delete;
if rent < 100 or rent > 10000 then delete;
run;

proc sort data=leases;
by current_status;
run;

* Creating Monthly Payment Var from Payment Vector;

data leases;
set leases;
month1=substr(rb_pay_vector,1,1);
month2=substr(rb_pay_vector,2,1);
month3=substr(rb_pay_vector,3,1);
month4=substr(rb_pay_vector,4,1);
month5=substr(rb_pay_vector,5,1);
month6=substr(rb_pay_vector,6,1);
month7=substr(rb_pay_vector,7,1);
month8=substr(rb_pay_vector,8,1);
month9=substr(rb_pay_vector,9,1);
month10=substr(rb_pay_vector,10,1);
month11=substr(rb_pay_vector,11,1);
month12=substr(rb_pay_vector,12,1);
month13=substr(rb_pay_vector,13,1);
month14=substr(rb_pay_vector,14,1);
month15=substr(rb_pay_vector,15,1);
month16=substr(rb_pay_vector,16,1);
month17=substr(rb_pay_vector,17,1);
month18=substr(rb_pay_vector,18,1);
month19=substr(rb_pay_vector,19,1);
month20=substr(rb_pay_vector,20,1);
month21=substr(rb_pay_vector,21,1);
month22=substr(rb_pay_vector,22,1);
month23=substr(rb_pay_vector,23,1);
month24=substr(rb_pay_vector,24,1);
run;
/*
proc freq data=leases;
	table lease_yr;
*	table rent;
	run;
*/
proc means data=leases noprint;
class property_id unit_id lease_yr;
var rent;
output out=property_year;
run;

data count_year;
	set property_year;
		where _type_ = 1 and
		_STAT_='N';
*		if _type_ = 1;
		run;

proc gchart data=count_year;
	vbar3d _freq_ / lease_yr;
run;	

proc sort data=leases;
	by property_id unit_id lease_yr;
	run;

data properties;
	set leases;
	by property_id unit_id lease_yr;
	if first.lease_yr;
	run;

proc means data=properties noprint;
class property_id unit_id lease_yr;
var rent;
output out=property_year;
run;

data property_year;
	set property_year;
		if _STAT_='N';
		run;

proc means data=property_year;
	class property_id lease_yr;
	var rent;
	output out=property_size;
	run;

data property_size;
	set property_size;
		if _STAT_='N';
		run;

proc freq data=properties;
	table lease_yr;
	run;

proc freq data=leases;
	table state;
	run;
